package org.example.studentsystem_back.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.example.studentsystem_back.common.CommonResponse;
import org.example.studentsystem_back.domain.Freshmen;
import org.example.studentsystem_back.dto.PageDTO;
import org.example.studentsystem_back.service.FreshmenService;
import org.example.studentsystem_back.vo.userManageVo.PageFreshmanVo;
import org.example.studentsystem_back.vo.freshmenMangeVo.FreshmenVo;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@Valid
public class FreshmenController {
    @Resource
    private FreshmenService freshmenService;

    //查询所有新生信息
    @PostMapping("/freshmen/page")
    public CommonResponse<PageFreshmanVo> getAllFreshmen(@RequestBody PageDTO pageDto) {
//        System.out.println(pageDto);
        return freshmenService.getAllFreshmen(pageDto);
    }

    //根据userId查询新生个人信息
    @GetMapping("/freshmen/{userId}")
    public CommonResponse<FreshmenVo> getFreshmenByUserId(@PathVariable("userId") String userId){
        return freshmenService.getFreshmenByUserId(userId);
    };

    //修改新生信息
    @PutMapping("/freshmen/{userId}")
    public CommonResponse<FreshmenVo> updateFreshmenUserId(@PathVariable("userId") String userId, @RequestBody Freshmen freshmen) {
        return freshmenService.updateFreshmenUserId(userId,freshmen);
    }

    //删除新生信息
    @DeleteMapping("/freshmen/{userId}")
    public CommonResponse<FreshmenVo> deleteFreshmen(@PathVariable("userId") String userId){
        return freshmenService.deleteFreshmen(userId);
    }

    //通过token获取当前新生信息
    @GetMapping("/freshmen/current")
    public CommonResponse<FreshmenVo> getCurrentFreshmen(HttpServletRequest httpServletRequest){
        return freshmenService.getCurrentFreshmen(httpServletRequest);
    }
}
